<!--
+----------------------------------------------------------------------
| 友得云客  - 开启房产营销新纪元
+----------------------------------------------------------------------
| Copyright (c) 2019~2023 优得（西安）信息科技有限公司版权所有
+----------------------------------------------------------------------
| Licensed 友得云客不是自由软件 未经允许不可移除相关版权
+----------------------------------------------------------------------
| Author: www.youdeyunke.com
+----------------------------------------------------------------------
-->
<template>
    <div class="profile" v-if="profile" v-cloak v-loading="loading">
        <el-table :data="tableData" :show-header="false">
            <el-table-column align="right" :width="150" prop="description"></el-table-column>
            <el-table-column prop="value"> </el-table-column>
        </el-table>
    </div>
</template>

<script>
import { getCustomerProfiles } from '@/api/report-customer.js'
export default {
    data () {

        return {
            profile: null,
            columns: [],
            loading: false,
        };
    },
    props: {
        userId: { type: Number },
    },

    watch: {
        userId: {
            immediate: true,
            deep: true,
            handler (val) {
                // pass
                if (!val) {
                    return;
                }
                this.loadData();
            },
        },

    },

    mounted: function () { },

    computed: {
        tableData: function () {
            var items = [];
            var p = this.profile;
            const descriptions = {
                // id: "ID",
                name: "姓名",
                mobile: "手机号码",
                age: "年龄",
                sex: "性别",
                customer_id: "客户ID",
                purchasing_urgency: "购买紧急度",
                intend_area: "意向面积",
                intend_room_type: "意向房型",
                intend_total: "意向总价",
                intend_single: "意向单价",
                purpose: "用途"
            };
            // var items = this.columns.map((c) => {
            //     var k = c.name
            //     var v = p[k]
            //     return { label: c.label, value: v }
            // })
            var items = Object.entries(this.profile).map(([key, value]) => ({ label: key, value: value, description: descriptions[key] || "" }))
            // delete items[0];
            items = items.filter(item => item.label !== 'customer_id');
            return items
        },
    },

    methods: {
        loadData () {
            this.loading = true
            var data = {
                customer_id: this.userId
            }
            getCustomerProfiles(data).then((resp) => {
                if(resp.code != 0) {
                    return
                }

                this.profile = resp.data
                this.loading = false
            })
            // getUserProfile(this.userId).then((res) => {
            //     this.profile = res.data
            //     this.columns = res.columns
            //     this.loading = false
            // })
        },
    },
};
</script>

<style scoped></style>